#include "driver/gpio.h"
#include "my_dev_config.h"
#include "my_led.h"
#include "esp_log.h"
#include "driver/ledc.h"

static const char *TAG = "MY_LED";




struct _led_state led_state[4] = {
    { LED_OFF, WIFI_INDICATOR_LED, "wifi indicator" },
    { LED_OFF, BLE_INDICATOR_LED,  "ble  indicator" },
    { LED_OFF, WORK_INDICATOR_LED, "work indicator" },
    { LED_OFF, INTERNET_INDICATOR_LED, "internet indicator" },
};

void led_operation(uint8_t pin, uint8_t onoff)
{
    for (int i = 0; i < sizeof(led_state); i++) {
        if (led_state[i].pin != pin) {
            continue;
        }
        if (onoff == led_state[i].previous) {
            ESP_LOGI(TAG, "led %s is already %s",led_state[i].name, (onoff ? "on" : "off"));
            return;
        }
        gpio_set_level(pin, onoff);
        led_state[i].previous = onoff;
        return;
    }
    ESP_LOGE(TAG, "LED is not found!");
}





void led_init(void)
{
    gpio_config_t io_conf;

    io_conf.intr_type = GPIO_INTR_DISABLE;
    io_conf.pin_bit_mask = ((1ULL << WORK_INDICATOR_LED) | (1ULL << INTERNET_INDICATOR_LED) | (1ULL << BLE_INDICATOR_LED) | (1ULL << WIFI_INDICATOR_LED));
    // io_conf.pin_bit_mask  = (1ULL << INTERNET_INDICATOR_LED);
    io_conf.mode = GPIO_MODE_OUTPUT;
    io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
    io_conf.pull_up_en = GPIO_PULLUP_DISABLE;    //上拉使能   
    
    gpio_config(&io_conf);
    gpio_set_level(WORK_INDICATOR_LED, 1);
    gpio_set_level(INTERNET_INDICATOR_LED, 1);
    gpio_set_level(BLE_INDICATOR_LED, 1);
    gpio_set_level(WIFI_INDICATOR_LED, 1);
}










